/*
 * TreeModel.h  0.4.0 / Dec 03, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#ifndef TREEMODEL_H
#define TREEMODEL_H

#include "Cute4jSwing.h"

// TreeNode Class. -------------------------------------------------------------

class TreeDelegate;

/*!
 * \brief Tree Node.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class CUTE4J_EXPORT TreeNode
{
public:
  TreeNode();
  TreeNode(jobject node, TreeNode *parent);
  virtual ~TreeNode();
public:
  jobject node();
  TreeNode *parent();
  QVariant data();
  int row();
  int childCount();
  bool isLeaf();
  TreeNode *child(int row);
  void addChild(TreeNode *child);
public:
  static void initialize(JNIEnv *env, jclass cls);
private:
  void expand();
private:
  jobject m_node;
  TreeNode *m_parentNode;
  int m_childCount;
  QList<TreeNode *> m_childNodes;
private:
  static jmethodID sm_getChildCountMID;
  static jmethodID sm_getChildAtMID;
};

// TreeModel Class. ------------------------------------------------------------

/*!
 * \brief Tree Model.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class CUTE4J_EXPORT TreeModel : public QAbstractItemModel
{
public:
  TreeModel(TreeDelegate *treeDelegate);
  virtual ~TreeModel();
public:
  TreeNode *getRootNode();
public:
  Qt::ItemFlags flags(const QModelIndex &index) const;
  QModelIndex parent(const QModelIndex &index) const;
  int rowCount(const QModelIndex &parent = QModelIndex()) const;
  int columnCount(const QModelIndex &parent = QModelIndex()) const;
  QModelIndex index(int row, int column,
                    const QModelIndex &parent = QModelIndex()) const;
  QVariant data(const QModelIndex &index, int role) const;
  QVariant headerData(int section, Qt::Orientation orientation,
                      int role = Qt::DisplayRole) const;
private:
  TreeDelegate *m_treeDelegate;
  TreeNode *m_rootNode;
  TreeNode *m_modelRootNode;
};

#endif // TREEMODEL_H
